package com.iofiledDemo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileIo {


    public static void main(String[] args) {

        FileIo fileIo = new FileIo();
        String filePath = "D:/upload/ioFile.txt";
        String result = fileIo.readFile(filePath);
        String fit = fileIo.fileRead(filePath);
        System.out.println(fit);
        System.out.println(result);

    }

    public String readFile(String filePath) {
        FileInputStream fis = null;
        String result = "";

        try {
            fis = new FileInputStream(filePath);
            int size = fis.available();
            byte[] array = new byte[size];
            fis.read(array);

            result = new String(array);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
            if(fis !=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }


            }
        }
        return  result;
    }



    public String fileRead(String filePath){


        String result = "";
        FileReader fileReader = null;

        try {
          fileReader = new FileReader(filePath);
            char[] charArray = new char[900];
           // int size = fileReader.available();
          //  fileReader.
            int num = 0;


         //   while((num = fileReader.read(charArray))!=-1) {

              fileReader.read(charArray);
             result = new String(charArray);
              //  System.out.println(result);


        //    }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException E){

        }finally {

            if(fileReader!=null) {
                try {
                    fileReader.close();

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


        return  result;
    }














}
